using System;

namespace Fornax020.SerialComm.Parsing
{
    /// <summary>
    /// 数据验证结果类
    /// </summary>
    public class ValidationResult
    {
        /// <summary>
        /// 验证是否通过
        /// </summary>
        public bool IsValid { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorMessage { get; set; }

        /// <summary>
        /// 私有构造函数
        /// </summary>
        private ValidationResult(bool isValid, string errorMessage = null)
        {
            IsValid = isValid;
            ErrorMessage = errorMessage;
        }

        /// <summary>
        /// 创建有效的验证结果
        /// </summary>
        /// <returns>有效的验证结果</returns>
        public static ValidationResult Valid()
        {
            return new ValidationResult(true);
        }

        /// <summary>
        /// 创建无效的验证结果
        /// </summary>
        /// <param name="errorMessage">错误信息</param>
        /// <returns>无效的验证结果</returns>
        public static ValidationResult Invalid(string errorMessage)
        {
            return new ValidationResult(false, errorMessage);
        }

        /// <summary>
        /// 获取字符串表示
        /// </summary>
        /// <returns>字符串表示</returns>
        public override string ToString()
        {
            return IsValid ? "验证通过" : $"验证失败: {ErrorMessage}";
        }
    }
}
